package com.zzy.base.activity;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentActivity;

import com.alibaba.android.arouter.launcher.ARouter;
import com.gyf.barlibrary.ImmersionBar;
import com.zzy.base.R;
import com.zzy.base.mvp.IBaseView;
import com.zzy.base.mvp.IBasePresenter;

import butterknife.ButterKnife;


public abstract class BaseActivity<P extends IBasePresenter> extends FragmentActivity implements IBaseView {
  public  P mPresenter;
    @SuppressLint("ResourceType")
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getLayoutId());
        initLayout(savedInstanceState);

        /**
         * 实例化和绑定 P 层
         */
        mPresenter = setPresenter();
        mPresenter.attach(this);


        initViews();
        initData();
        
        ARouter.getInstance().inject(this);
    }
    protected abstract int getLayoutId();
    protected abstract void initViews();

    protected abstract void initData();

    protected abstract P setPresenter();

    protected abstract void initLayout(Bundle savedInstanceState);


    @Override
    public void onPointerCaptureChanged(boolean hasCapture) {

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mPresenter.detech();
        mPresenter=null;
    }

    @Override
    public Context getContext() {
        return this;
    }
}
